package com.api.client;
public enum ResponseStatus {
		
		OK(HttpStatusType.SUCCESS, 200),
		
		MOVED_TEMPORARILY(HttpStatusType.REDIRECTION, 302),
		
		BAD_REQUEST(HttpStatusType.CLIENT_ERROR, 400),
		
		UNAUTHORIZED(HttpStatusType.CLIENT_ERROR, 401),
		
		FORBIDDEN(HttpStatusType.CLIENT_ERROR, 403),
		
		NOT_FOUND(HttpStatusType.CLIENT_ERROR, 404),
		
		NOT_ALLOWED(HttpStatusType.CLIENT_ERROR, 405),
		
		UNSUPPORTED_MEDIA_TYPE(HttpStatusType.CLIENT_ERROR, 415),
		
		INTERNAL_SERVER_ERROR(HttpStatusType.SERVER_ERROR, 500),
		
		BAD_GATEWAY(HttpStatusType.SERVER_ERROR, 502),
		
		SERVICE_UNAVAILABLE(HttpStatusType.SERVER_ERROR, 503)
		;
		
		public enum HttpStatusType{
			
			INFORMATIONAL, SUCCESS, REDIRECTION, CLIENT_ERROR, SERVER_ERROR;
		}
		
		private int code;
		
		private HttpStatusType status;
		
		private ResponseStatus(HttpStatusType status, int code){
			
			this.code = code;
			
			this.status = status;
		}
		
		public int getCode(){
			return code;
		}
		
		public HttpStatusType getStatusType(){
			return status;
		}
		
		public String toString(){
			
			return super.toString() + "(" + status.toString() + ":" + code + ")";
		}
		
		public static ResponseStatus valueOf(int code) {
			
			ResponseStatus key = null;
			
			if( code > 100 && code < 600){
			
				ResponseStatus[] array = ResponseStatus.values();
			
				int i = 0;
			
				while (i < array.length && key == null){
				
					if(array[i].getCode() == code){
					
						key = array[i];
					}
					else{
						i++;
					}
				}
			}
			if (key != null){
				
				return key;
			}
			else{
			
				throw new IllegalArgumentException(String.format("The http status code %s is not supported", code));
			}
		}
	}